import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenTwoRouter, ExamineButton } from '../Common/options'
import { SuperviseTypeTree } from '../Common/Conversion'

const { hostname } = window.location

// 'jtgj.ljkjkf.com'

export const Supervise = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    Permission = Permission.find(v => v.targetUrl === url).children
    const superviseTypeUuid = await SuperviseTypeTree()

    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        // hideInSearch: true,
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission.findIndex(v => v.uuid === 'b9a52b13-c855-4c49-ae93-e06dbe5eeb36') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            { ...commonTableList.tableName, title: '主题' },
            {
                dataIndex: 'superviseTypeUuid',
                title: '类型',
                valueType: 'treeSelect',
                fieldProps: {
                    options: superviseTypeUuid,
                    fieldNames: { label: 'tableName', value: 'uuid' },
                },
                rules: true,
                hideInSearch: true,
                hideInTable: true,
                width: 250,
            },
            {
                dataIndex: 'superviseTypeFullName',
                title: hostname === 'jtgj.ljkjkf.com' ? '风险点类型' : '工序类型',
                valueType: 'inputNumber',
                rules: true,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
                width: 300,
            },
            {
                dataIndex: 'approvalStatus',
                title: '状态',
                valueType: 'select',
                valueEnum: hostname === 'jtgj.ljkjkf.com' ? BuiltInData.riskStatus : BuiltInData.SuperviseStatus,
                hideInAdded: true,
                hideInModify: true,
                rules: true,
                width: 150,
            },
            commonTableList.remark,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 400,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, approvalStatus } = record
                    return [
                        <OpenTwoRouter
                            key="TwoOne"
                            title="附件明细"
                            modal="TableList"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'Supervise',
                                actionRef,
                                Permission,
                                oneData: record,
                                header: data.columns,
                            }}
                        />,
                        <OpenTwoRouter
                            key="TwoTwo"
                            title="摄像头列表"
                            modal="TableList"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'SuperviseCamera',
                                Permission,
                                oneData: record,
                                header: data.columns,
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === 'e921eda5-09ad-4a25-bead-79016646db19') !== -1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        Permission.findIndex(v => v.uuid === 'b6ef909a-7ea0-4a2c-9285-5cb9171b57da') !== -1 &&
                            approvalStatus === 0 && (
                                <ExamineButton
                                    key="one"
                                    title="提交"
                                    data={{
                                        actionRef,
                                        OptionsEvent,
                                        url: 'posSuperviseSubmit',
                                        smallTitle: '提交监理工序审核',
                                    }}
                                    options={[
                                        { title: '提交', type: 'primary', emit: { path: [uuid] } },
                                        { title: '取消', type: 'link', emit: 'off' },
                                    ]}
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'b6ef909a-7ea0-4a2c-9285-5cb9171b57da') !== -1 &&
                            approvalStatus === 1 && (
                                <ExamineButton
                                    key="one"
                                    title="审核"
                                    data={{
                                        actionRef,
                                        OptionsEvent,
                                        url: 'posSuperviseApproval',
                                        smallTitle: '监理工序',
                                    }}
                                    options={[
                                        {
                                            title: hostname === 'jtgj.ljkjkf.com' ? '通过' : '合格',
                                            type: 'primary',
                                            emit: { path: [uuid, 2] },
                                        },
                                        {
                                            title: hostname === 'jtgj.ljkjkf.com' ? '不通过' : '不合格',
                                            type: 'link',
                                            danger: true,
                                            emit: { path: [uuid, 3] },
                                        },
                                    ]}
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'b6ef909a-7ea0-4a2c-9285-5cb9171b57da') !== -1 &&
                            approvalStatus === 2 && (
                                <ExamineButton
                                    key="one"
                                    title={hostname === 'jtgj.ljkjkf.com' ? '不通过' : '不合格'}
                                    danger={true}
                                    data={{
                                        actionRef,
                                        OptionsEvent,
                                        url: 'posSuperviseApproval',
                                        smallTitle: '监理工序',
                                    }}
                                    options={[
                                        {
                                            title: hostname === 'jtgj.ljkjkf.com' ? '不通过' : '不合格',
                                            type: 'primary',
                                            emit: { path: [uuid, 3] },
                                        },
                                        { title: '取消', type: 'link', emit: 'off' },
                                    ]}
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'b6ef909a-7ea0-4a2c-9285-5cb9171b57da') !== -1 &&
                            approvalStatus === 3 && (
                                <ExamineButton
                                    key="one"
                                    title={hostname === 'jtgj.ljkjkf.com' ? '通过' : '合格'}
                                    data={{
                                        actionRef,
                                        OptionsEvent,
                                        url: 'posSuperviseApproval',
                                        smallTitle: '监理工序',
                                    }}
                                    options={[
                                        {
                                            title: hostname === 'jtgj.ljkjkf.com' ? '通过' : '合格',
                                            type: 'primary',
                                            emit: { path: [uuid, 2] },
                                        },
                                        { title: '取消', type: 'link', emit: 'off' },
                                    ]}
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '1d97516b-3364-4d79-abe5-769d09e74fe1') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
